const mongoose = require('mongoose')
const dotenv = require('dotenv')

/**
 * 指定环境变量文件的路径
 * dotenv会读取这些变量，然后写道nodejs的环境变量目录中
 */
dotenv.config({ path: './config.env' })
const app = require('./app')
const client = require('./utils/redisClient')

/**
 * 连接 mongodb
 */
const DB = process.env.LOCAL_DATABASE
mongoose.connect(DB).then(() => {
  console.log('DB connection successful 👍')
})

/**
 * 连接redis
 */
client.connectRedis().then(() => {
  console.log('Redis connection successful 👍')
})

/**
 * 配置express
 */
const port = process.env.PORT || 3000
app.listen(port, () => {
  console.log(`App running at http://localhost:${port} 👍`)
})
